﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace counter2
{
    public partial class calculator2 : Form
    {
        public calculator2()
        {
            InitializeComponent();
        }
        public int n1=0, n2=0;
        public string opr="";

        private void txtnum2_TextChanged(object sender, EventArgs e)
        {
            n2 = int.Parse(txtnum2.Text);
        }

        private void txtnum1_TextChanged(object sender, EventArgs e)
        {
            n1 = int.Parse(txtnum1.Text);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            opr=comboBox1.Text;
        }

        private void counter2_Load(object sender, EventArgs e)
        {
            My_Combobox();
        }

        private void btnRes_Click(object sender, EventArgs e)
        {
            int res = 0;
            switch (opr)
            {
                case "+":
                    res = n1 + n2; break;
                case "-":
                    res = n1 - n2;break;
                case "*":                   
                    res = n1 * n2; break;
                case "/":
                    if(n2 == 0)
                    {
                        MessageBox.Show("The second number can't be 0.");
                        return;
                    }
                    res = n1 / n2; break;
                default:
                    MessageBox.Show("请选择运算符！");
                    return ;
                    break;

            }
            MessageBox.Show("计算结果为：" + res);
        }

        public void My_Combobox()
        {
            comboBox1.Items.Add("+");//选择项1
            comboBox1.Items.Add("_");
            comboBox1.Items.Add("*");
            comboBox1.Items.Add("/");
        }
    }
}
